<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?>
<title><?= $sf_response->getTitle() ?></title>
<?php use_stylesheet('/sf/sf_admin/css/main') ?>

<div id="sf_admin_container">

<h1>View <?php echo $mr3->getMrno() ?></h1>

<div id="sf_admin_content">

<fieldset id="sf_fieldset_none" class="">
<?php
    if ($mr3->getReviseId()) { ?>
        <input type="hidden" name="mr3[revise_id]" id="mr3[revise_id]" value="<?php echo $mr3->getReviseId() ?>" >
<?}
?>

<div class="form-row">
  <?php echo label_for('mr3[mrno]', __($labels['mr3{mrno}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('mr3{mrno}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr3{mrno}')): ?>
    <?php echo form_error('mr3{mrno}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

 <!--Tien code here-->
  <?php $default = CommonValues::GenerateAutoNumber('MR3', $mr3->getMrno(), 'MRRAW')   ?>
   
   <input name="mr2_mrno_show" id="mr2_mrno_show" value="<?php echo $default ?>" size="15" disabled="disabled" type="text">
   </div>
</div>

<div class="form-row">
  <?php echo label_for('mr3[category]', __($labels['mr3{category}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr3{category}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr3{category}')): ?>
    <?php echo form_error('mr3{category}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <input type="hidden" name = "mr3[category]" id ="mr3_category" value="<?php echo CommonValues::$gMRCategory['key']['Stock']?>"/>
  <input type="text" name = "mr3_show_category" id ="mr3_show_category" disabled = "1" size = "5" value="Stock"/>
    </div>
</div>

<div class="form-row">
  <?php echo label_for('mr3[reqarrdate]', __($labels['mr3{reqarrdate}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr3{reqarrdate}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr3{reqarrdate}')): ?>
    <?php echo form_error('mr3{reqarrdate}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_input_date_tag($mr3, 'getReqarrdate', array (
  'rich' => true,
  'calendar_button_img' => '/sf/sf_admin/images/date.png',
  'control_name' => 'mr3[reqarrdate]',
      'disabled'=>'disabled'
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>


<div class="form-row">
  <?php echo label_for('mr3[status]', __($labels['mr3{status}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr3{status}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr3{status}')): ?>
    <?php echo form_error('mr3{status}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php  $status = $mr3->getStatus()?  $mr3->getStatus(): 0?> 
  <input type="text" name ="mr_show" id ="mr_show" disabled="1"  value="<?php echo CommonValues::$gMRStatus['value'][$status]?>">
  <input type="hidden" name ="mr3[status]" id ="mr3_status" value="<?php echo $status?>">
    </div>
</div>

<div class="form-row">
  <?php echo label_for('mr3[approvalstatus]', __($labels['mr3{approvalstatus}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr3{approvalstatus}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr3{approvalstatus}')): ?>
    <?php echo form_error('mr3{approvalstatus}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php  $status = $mr3->getApprovalstatus()?  $mr3->getApprovalstatus(): 0?> 
  <input type="text" name ="mr_show" id ="mr_show" disabled="1"  value="<?php echo CommonValues::$gMRApprovalStatus['value'][$status]?>">
  <input type="hidden" name ="mr3[approvalstatus]" id ="mr3_approvalstatus" value="<?php echo $status?>">
    </div>
</div>


<div class="form-row">
  <?php echo label_for('mr3[notes]', __($labels['mr3{notes}']), '') ?>
    <div class="content">

  <?php $value = object_textarea_tag($mr3, 'getNotes', array (
  'size' => '50x5',
  'control_name' => 'mr3[notes]',
  'disabled'=>1,
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>
</fieldset>

<!--Tien code here
get information for MR-->
<?php
    if ($mr3->getComponentgroupId()){
        $componentGroupId = $mr3->getComponentgroupId();
        
        $c = new Criteria();
        $c->add(ComponentsPeer::COMPONENTGROUP_ID , $componentGroupId);
        $c->addAscendingOrderByColumn(ComponentsPeer::ID);
        
        $componentList = ComponentsPeer::doSelect($c);
    }
?>


<?php 
echo link_to_remote('', array('update' => 'list_component', 
  'url' => 'component/listAjax', 
  'loading' => visual_effect('appear', 'indicator'),
  'complete' => visual_effect('fade', 'indicator'). visual_effect('highlight', 'list_component'),
  'position' => 'bottom',
));
?>

<table id ='added_components' "cellspacing="0" class="sf_admin_list">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" width="25%">Product Code </th>
      <th id="sf_admin_list_th_description" width="35%">Description</th>
      <th id="sf_admin_list_th_description" width="10%">Brand</th>       
      <th id="sf_admin_list_th_description" width="5%">Unit
              </th>
      <th id="sf_admin_list_th_description" width="5%">Exp Dlv Date (dd-mm-yy)</th>
      
      <th id="sf_admin_list_th_description">Qty to request</th>
</tr>
</thead>
<!--show component here-->
<?php if (isset($mr3->rowIds) && count($mr3->rowIds)) {
    foreach ($mr3->rowIds as $key=>$id) { 
        $component1= ComponentPeer::retrieveByPK($id);?>
        <tr class="sf_admin_row_<?php echo $key%2?>">
            <input type="hidden" name="rowIds[]" id ="rowIds"  class = "ExistComponents" value="<? echo $component1->getId()?>"/>
            <td><?echo $component1->getProductcode()?></td>
            <td><?echo $component1->getDescription()?></td>
            <td><?echo $component1->getBrand()?></td>
            <td><?echo $component1->getComponentunit()?></td>
            <td><input type="text" name="expdates[]" id ="expdates" size="8" value ="<?echo $mr3->expdates[$key]?>"></td>
            <td><input type="text" name="qtys[]" id ="qtys" size="5" class="QTYS" value ="<?echo $mr3->qtys[$key]?>"></td>
            <td><ul class="sf_admin_td_actions"><li><?php echo  image_tag(sfConfig::get('sf_admin_web_dir').'/images/delete_icon.png', array('align' => 'absmiddle', 'alt' => 'delete', 'title' =>'delete', 'onclick' => 'removeComponent('.$component1->getId().',"added_components", ".ExistComponents")', 'onmouseover'=>'this.style.cursor="pointer"'))?></li></ul></td>
        </tr>
<?} } elseif (isset($componentList) && $componentList) {
    foreach ($componentList as $key=>$components) { 
        $component1= ComponentPeer::retrieveByPK($components->getComponentId());
        ?>
        <tr class="sf_admin_row_<?php echo $key%2?>">
            <input type="hidden" name="rowIds[]" id ="rowIds"  class = "ExistComponents" value="<? echo $component1->getId()?>"/>
            <td><?echo $component1->getProductcode()?></td>
            <td><?echo $component1->getDescription()?></td>
            <td><?echo $component1->getBrand()?></td>
            <td><?echo $component1->getComponentunit()?></td>   
            <td><input type="text" name="expdates[]" disabled id ="expdates" size="8" value ="<?echo $components->getDate("d-m-Y")?>"></td>
            <td><input type="text" name="qtys[]" disabled id ="qtys" size="5" class="QTYS"  value ="<?echo $components->getQty1()?>"></td>
        </tr>
<?php } }?>
</table>

</div>

</div>